package cn.edu.jlu.community.server;

public class KeyGen{
	public static char [] run(char [] str) throws Exception{
		
		if(str.length!=6)
			throw new Exception("str need 6 for length");
		for(int i = 0 ; i < 6; i++)
			if(str[i] - 48 > 7 || str[i] - 48 < 0)
				throw new Exception("u can input 0-9");
		
		int[] s1 = {0,0,0};
		int sp1 = 0;
		int[] s2 = {0,0,0};
		int sp2 = 0;
		char[] res = {'0','0','0','0','0','0','0','0'};
		
		res[0] = str[0];
		
		for(int i = 0; i < 3; i++){
			res[i + 1] = str[i + 1];
			if(res[i + 1] == res[i]){
				res[i + 1] = (char)((res[i + 1] - 48 + 1) % 8 + 48);
				s1[i] = 1;
			}
		}
		
		for(int i = 0; i < 2; i++){
			res[i + 4] = str[i + 4];
			if(res[i + 4] == res[i + 3]){
				res[i + 4] = (char)((res[i + 4] - 48 + 1) % 8 + 48);
				s2[i] = 1;
			}
		}
		
		for(int i = 0; i < 3; i++){
			if(s1[i] == 1)
				sp1 = sp1 + (int)Math.pow(2, 2 - i);
			if(s2[i] == 1)
				sp2 = sp2 + (int)Math.pow(2, 2 - i);
		}
		
		if(sp1 == sp2){
			sp2 ++;
		}
		
		res[6] = (char)(sp1 + 48);
		res[7] = (char)(sp2 + 48);
		return res;
	}
}
